/* eslint-disable no-dupe-class-members */
'use strict';

const BaseService = require('./base');

class ThemeImage extends BaseService {
  // 上传七牛云链接
  async addThemeImage(params) {
        
    const { ctx } = this;

    // 查询数据是否存在
    const currentImage = await ctx.model.ThemeImage.findOne({
      where: {
        theme_id: params.theme_id,
      }
    });
    if (currentImage) {  // 更新照片
      return await ctx.model.ThemeImage.update({image: params.image}, {
        where: {
          theme_id: params.theme_id,
        }
      });
    }
    
    // 新增
    return await ctx.model.ThemeImage.create(params); 
  }
}

module.exports = ThemeImage;
